package com.example.service;

import com.example.entity.Account;
import com.example.entity.Asset;
import com.example.mapper.AssetMapper;
import com.example.utils.TokenUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AssetService {

    @Resource
    AssetMapper assetMapper;

    public void add(Asset asset) {
        assetMapper.insert(asset);
    }

    public void update(Asset asset) {
        Account currentUser = TokenUtils.getCurrentUser();
        assetMapper.updateById(asset);
    }

    public void deleteById(Integer id) {
        assetMapper.deleteById(id);
    }

    public List<Asset> selectAll(Asset asset) {
        return assetMapper.selectAll(asset);
    }

    public PageInfo<Asset> selectPage(Integer pageNum, Integer pageSize, Asset asset) {
        // 开启分页查询
        PageHelper.startPage(pageNum, pageSize);
        List<Asset> list = assetMapper.selectAll(asset);
        return PageInfo.of(list);
    }
}
